<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>插入排序</title>
</head>
<body>
<h3>插入排序</h3>
<script>
	function insertionSort(arr){
		var len = arr.length;
		var preIndex,current;
		for(var i =1;i<len;i++){
			preIndex = i - 1;
			current = arr[i];
			while(preIndex >=0 && arr[preIndex] > current){
				arr[preIndex +1] =arr[preIndex];
				preIndex--;
			}
			arr[preIndex+1] =current
		}
		return arr;
	}
	console.log( insertionSort([1,3,2,3,5]) )
</script>
</body>
</html>
